#include "common/config/config.h"

const char *auth = "d6ff7a979fa2";
const char *ssid = "Xiaomi_FB1A";
const char *password = "12121616";
unsigned char needOTA = 0;
const char *aPSsid = "bihua";
const char *aPPassword = "11111111";

const String configFile = "/config.json";
ConfigData configData;

unsigned int servoDefaultAngle = 90;
unsigned int servoDefaultStopTime = 500;

void loadConfigData()
{
    String str = readFile(configFile);
    StaticJsonDocument<1024> doc;
    DeserializationError error = deserializeJson(doc, str);
    if (error)
    {
        return;
    }
    configData.servoAngle = (unsigned char)String(doc["servoAngle"]).toInt();
    configData.servoStopTime = (unsigned char)String(doc["servoStopTime"]).toInt();
    configData.md5 = String(doc["md5"]);
}
void saveConfigData()
{
    StaticJsonDocument<1024> doc;
    doc["servoAngle"] = configData.servoAngle;
    doc["servoStopTime"] = configData.servoStopTime;
    String strmd5, str;
    serializeJson(doc, strmd5);
    String md5 = md5String(strmd5);
    if (md5 == configData.md5)
    {
        return;
    }

    configData.md5 = md5;
    doc["md5"] = configData.md5;
    serializeJson(doc, str);
    writeFile(configFile, str);
}